package edu.ynu.hhy.architectureclass.service;

import edu.ynu.hhy.architectureclass.common.service.LogicService;
import edu.ynu.hhy.architectureclass.dao.GreenhouseDao;
import edu.ynu.hhy.architectureclass.entity.Greenhouse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class GreenhouseService extends LogicService<GreenhouseDao, Greenhouse, Long> {

    @Autowired
    public GreenhouseService(GreenhouseDao greenhouseDao) {
        super(greenhouseDao);
    }

    /**
     * 获取大棚详细信息（包含设备数量）
     *
     * @param id 大棚ID
     * @return 包含设备数量的大棚详细信息
     */
    public Greenhouse getGreenhouseDetailWithDeviceCount(Long id) {
        Greenhouse greenhouse = GET(id);
        if (greenhouse != null) {
            // 获取设备数量（假设大棚类中有 devices 字段）
            int deviceCount = greenhouse.getDevices().size();
            greenhouse.setDeviceCount(deviceCount);
        }
        return greenhouse;
    }
}